package com.cn.lycss.dao.impl;

import com.cn.lycss.dao.CuisineDao;
import com.cn.lycss.model.CuisineModel;
import com.cn.lycss.util.JDBC;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CuisineImpl implements CuisineDao {
    @Override
    public Integer getCount(CuisineModel model) {
        return 0;
    }

    @Override
    public List<CuisineModel> findAll(CuisineModel model) {
//        String sql = "select * from cuisine where is_show=" + model.getIsShow();
        String sql = "select * from cuisine where is_show=1";
        ResultSet resultSet = JDBC.query(sql);
        List<CuisineModel> list = new ArrayList<>();
        try {
            while (resultSet.next()){
                CuisineModel cuisineModel = new CuisineModel();
                cuisineModel.setId(resultSet.getInt("id"));
                cuisineModel.setName(resultSet.getString("name"));
                list.add(cuisineModel);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }

//    private List<CuisineModel> getList(String sql) {
//        ResultSet resultSet = JDBC.query(sql);
//        List<CuisineModel> list = new ArrayList<>();
//        try {
//            while (resultSet.next()) {
//                CuisineModel model = new CuisineModel();
//
//                model.setId(resultSet.getInt("id"));
//
//                model.setName(resultSet.getString("name"));
//                model.setTitle(resultSet.getString("is_name"));
//                model.setIsShow(resultSet.getInt("is_show"));
//
//                list.add(model);
//            }
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
//        return list;
//    }
}
